package manager.entitycreator;

import java.sql.ResultSet;
import java.sql.SQLException;

import util.DateUtil;
import entity.Course;
import entity.Section;

/**
 * Implements methods that describe how to extract section information from the
 * given ResultSet.
 * 
 * @author sheryl.tay.2012, mohameds.2012
 * 
 */
public class SectionCreator implements EntityCreator<Section> {

	@Override
	public Section newEntityFromResultSet(ResultSet rs) throws SQLException {
		return newSectionFromResultSet(rs);
	}

	/**
	 * Creates a new Section entity from the given result set.
	 * 
	 * @param rs
	 *            result set containing course and section information
	 * @return a new Section entity with information extracted from the result
	 *         set
	 * @throws SQLException
	 */
	static Section newSectionFromResultSet(ResultSet rs) throws SQLException {

		Course course = CourseCreator.newCourseFromResultSet(rs);

		Section section = new Section(course,
				rs.getString("section_sectionCode"), rs.getInt("section_day"),
				DateUtil.convertToDate(rs.getString("section_startTime"),
						DateUtil.MYSQL_TIME_PATTERN), DateUtil.convertToDate(
						rs.getString("section_endTime"),
						DateUtil.MYSQL_TIME_PATTERN),
				rs.getString("section_instructor"),
				rs.getString("section_venue"), rs.getInt("section_size"));

		return section;
	}

}
